package org.lboot.ufs.entity;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.Hibernate;
import org.lboot.jpa.entity.BaseEntity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Objects;

/**
 * @author kindear
 */
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "ufs_file")
@ApiModel(value = "文件实体",description = "")
public class UfsFile extends BaseEntity implements Serializable {

    /**
     * 根据存储模式去装载 s3Client 客户端
     */
    @ApiModelProperty("存储模式")
    @Column(name = "storage_mode")
    private String storageMode;


    @ApiModelProperty("存储桶名称")
    @Column(name = "bucket_name")
    private String bucketName;

    @ApiModelProperty("对象名称前缀")
    @Column(name = "prefix")
    private String prefix;

    @ApiModelProperty("存储对象名称")
    @Column(name = "object_name")
    private String objectName;

    @ApiModelProperty(value = "文件名")
    @Column(name = "file_name")
    private String fileName;

    @ApiModelProperty(value = "拓展名")
    @Column(name = "ext_name")
    private String extName;

    @ApiModelProperty(value = "文件大小")
    @Column(name = "file_size")
    private Long fileSize;

    @ApiModelProperty(value = "文件状态",notes = "0 为禁止访问 1 为正常")
    @Column(name = "status")
    private Integer status;

    /**
     * 如何理解文件类型 文档 / 图片 / 视频 / 回收站
     */
    @ApiModelProperty(value = "文件类型",notes = "")
    @Column(name = "file_type")
    private String fileType;

    @ApiModelProperty(value = "唯一识别编码")
    @Column(name = "md5")
    private String md5;

    @ApiModelProperty(value = "只读")
    @Column(name = "read_only")
    private Integer readOnly;


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        UfsFile that = (UfsFile) o;
        return getId() != null && Objects.equals(getId(), that.getId());
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}
